package io.github.biezhi.java8.completablefuture;

import java.util.concurrent.*;

/**
 * 创建 CompletableFuture
 *
 * @author biezhi
 * @date 2018/3/25
 */
public class CompletableFuture1 {

    public static void main(String[] args) {

//        ExecutorService executorService = Executors.newFixedThreadPool(5);
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5,
                10,
                1,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>());

        CompletableFuture<Void> helloFuture = CompletableFuture.runAsync(() -> System.out.println("hello future"), threadPoolExecutor);

        for (int i = 0; i < 10; i++) {
            CompletableFuture<String> integerCompletableFuture = CompletableFuture.supplyAsync(() -> Thread.currentThread().getName() + "-2333", threadPoolExecutor);
            try {
                System.out.println(integerCompletableFuture.get());
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            } catch (ExecutionException e) {
                throw new RuntimeException(e);
            }
        }


        threadPoolExecutor.shutdown();
    }
}
